<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>loremipsum_test.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_editor_plugins_loremipsum_test.js.html">loremipsum_test.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2008 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>goog.provide(&#39;goog.editor.plugins.LoremIpsumTest&#39;);
<a name="line16"></a>goog.setTestOnly(&#39;goog.editor.plugins.LoremIpsumTest&#39;);
<a name="line17"></a>
<a name="line18"></a>goog.require(&#39;goog.dom&#39;);
<a name="line19"></a>goog.require(&#39;goog.editor.Command&#39;);
<a name="line20"></a>goog.require(&#39;goog.editor.Field&#39;);
<a name="line21"></a>goog.require(&#39;goog.editor.plugins.LoremIpsum&#39;);
<a name="line22"></a>goog.require(&#39;goog.string.Unicode&#39;);
<a name="line23"></a>goog.require(&#39;goog.testing.jsunit&#39;);
<a name="line24"></a>goog.require(&#39;goog.userAgent&#39;);
<a name="line25"></a>
<a name="line26"></a>var FIELD;
<a name="line27"></a>var PLUGIN;
<a name="line28"></a>var HTML;
<a name="line29"></a>var UPPERCASE_CONTENTS = &#39;&lt;P&gt;THE OWLS ARE NOT WHAT THEY SEEM.&lt;/P&gt;&#39;;
<a name="line30"></a>
<a name="line31"></a>function setUp() {
<a name="line32"></a>  HTML = goog.dom.getElement(&#39;root&#39;).innerHTML;
<a name="line33"></a>
<a name="line34"></a>  FIELD = new goog.editor.Field(&#39;field&#39;);
<a name="line35"></a>
<a name="line36"></a>  PLUGIN = new goog.editor.plugins.LoremIpsum(
<a name="line37"></a>      &#39;The owls are not what they seem.&#39;);
<a name="line38"></a>  FIELD.registerPlugin(PLUGIN);
<a name="line39"></a>}
<a name="line40"></a>
<a name="line41"></a>function tearDown() {
<a name="line42"></a>  FIELD.dispose();
<a name="line43"></a>  goog.dom.getElement(&#39;root&#39;).innerHTML = HTML;
<a name="line44"></a>}
<a name="line45"></a>
<a name="line46"></a>function testQueryUsingLorem() {
<a name="line47"></a>  FIELD.makeEditable();
<a name="line48"></a>
<a name="line49"></a>  assertTrue(FIELD.queryCommandValue(goog.editor.Command.USING_LOREM));
<a name="line50"></a>  FIELD.setHtml(true, &#39;fresh content&#39;, false, true);
<a name="line51"></a>  assertFalse(FIELD.queryCommandValue(goog.editor.Command.USING_LOREM));
<a name="line52"></a>}
<a name="line53"></a>
<a name="line54"></a>function testUpdateLoremIpsum() {
<a name="line55"></a>  goog.dom.getElement(&#39;field&#39;).innerHTML = &#39;stuff&#39;;
<a name="line56"></a>
<a name="line57"></a>  var loremPlugin = FIELD.getPluginByClassId(&#39;LoremIpsum&#39;);
<a name="line58"></a>  FIELD.makeEditable();
<a name="line59"></a>  var content = &#39;&lt;div&gt;foo&lt;/div&gt;&#39;;
<a name="line60"></a>
<a name="line61"></a>  FIELD.setHtml(false, &#39;&#39;, false, /* Don&#39;t update lorem */ false);
<a name="line62"></a>  assertFalse(&#39;Field started with content, lorem must not be enabled.&#39;,
<a name="line63"></a>      FIELD.queryCommandValue(goog.editor.Command.USING_LOREM));
<a name="line64"></a>  FIELD.execCommand(goog.editor.Command.UPDATE_LOREM);
<a name="line65"></a>  assertTrue(&#39;Field was set to empty, update must turn on lorem ipsum&#39;,
<a name="line66"></a>      FIELD.queryCommandValue(goog.editor.Command.USING_LOREM));
<a name="line67"></a>
<a name="line68"></a>  FIELD.unregisterPlugin(loremPlugin);
<a name="line69"></a>  FIELD.setHtml(false, content, false,
<a name="line70"></a>      /* Update (turn off) lorem */ true);
<a name="line71"></a>  FIELD.setHtml(false, &#39;&#39;, false, /* Don&#39;t update lorem */ false);
<a name="line72"></a>  FIELD.execCommand(goog.editor.Command.UPDATE_LOREM);
<a name="line73"></a>  assertFalse(&#39;Field with no lorem message must not use lorem ipsum&#39;,
<a name="line74"></a>      FIELD.queryCommandValue(goog.editor.Command.USING_LOREM));
<a name="line75"></a>  FIELD.registerPlugin(loremPlugin);
<a name="line76"></a>
<a name="line77"></a>  FIELD.setHtml(false, content, false, true);
<a name="line78"></a>  FIELD.setHtml(false, &#39;&#39;, false, false);
<a name="line79"></a>  goog.editor.Field.setActiveFieldId(FIELD.id);
<a name="line80"></a>  FIELD.execCommand(goog.editor.Command.UPDATE_LOREM);
<a name="line81"></a>  assertFalse(&#39;Active field must not use lorem ipsum&#39;,
<a name="line82"></a>      FIELD.queryCommandValue(goog.editor.Command.USING_LOREM));
<a name="line83"></a>  goog.editor.Field.setActiveFieldId(null);
<a name="line84"></a>
<a name="line85"></a>  FIELD.setHtml(false, content, false, true);
<a name="line86"></a>  FIELD.setHtml(false, &#39;&#39;, false, false);
<a name="line87"></a>  FIELD.setModalMode(true);
<a name="line88"></a>  FIELD.execCommand(goog.editor.Command.UPDATE_LOREM);
<a name="line89"></a>  assertFalse(&#39;Must not turn on lorem ipsum while a dialog is open.&#39;,
<a name="line90"></a>      FIELD.queryCommandValue(goog.editor.Command.USING_LOREM));
<a name="line91"></a>  FIELD.setModalMode(true);
<a name="line92"></a>
<a name="line93"></a>  FIELD.dispose();
<a name="line94"></a>}
<a name="line95"></a>
<a name="line96"></a>function testLoremIpsumAndGetCleanContents() {
<a name="line97"></a>  goog.dom.getElement(&#39;field&#39;).innerHTML = &#39;This is a field&#39;;
<a name="line98"></a>  FIELD.makeEditable();
<a name="line99"></a>
<a name="line100"></a>  // test direct getCleanContents
<a name="line101"></a>  assertEquals(&#39;field reported wrong contents&#39;, &#39;This is a field&#39;,
<a name="line102"></a>      FIELD.getCleanContents());
<a name="line103"></a>
<a name="line104"></a>  // test indirect getCleanContents
<a name="line105"></a>  var contents = FIELD.getCleanContents();
<a name="line106"></a>  assertEquals(&#39;field reported wrong contents&#39;, &#39;This is a field&#39;, contents);
<a name="line107"></a>
<a name="line108"></a>  // set field html, but explicitly forbid converting to lorem ipsum text
<a name="line109"></a>  FIELD.setHtml(false, &#39;&amp;nbsp;&#39;, true, false /* no lorem */);
<a name="line110"></a>  assertEquals(&#39;field contains unexpected contents&#39;, getNbsp(),
<a name="line111"></a>      FIELD.getElement().innerHTML);
<a name="line112"></a>  assertEquals(&#39;field reported wrong contents&#39;, getNbsp(),
<a name="line113"></a>      FIELD.getCleanContents());
<a name="line114"></a>
<a name="line115"></a>  // now set field html allowing lorem
<a name="line116"></a>  FIELD.setHtml(false, &#39;&amp;nbsp;&#39;, true, true /* lorem */);
<a name="line117"></a>  assertEquals(&#39;field reported wrong contents&#39;, goog.string.Unicode.NBSP,
<a name="line118"></a>      FIELD.getCleanContents());
<a name="line119"></a>  assertEquals(&#39;field contains unexpected contents&#39;, UPPERCASE_CONTENTS,
<a name="line120"></a>      FIELD.getElement().innerHTML.toUpperCase());
<a name="line121"></a>}
<a name="line122"></a>
<a name="line123"></a>function testLoremIpsumAndGetCleanContents2() {
<a name="line124"></a>  // make a field blank before we make it editable, and then check
<a name="line125"></a>  // that making it editable activates lorem.
<a name="line126"></a>  assert(&#39;field is editable&#39;, FIELD.isUneditable());
<a name="line127"></a>  goog.dom.getElement(&#39;field&#39;).innerHTML = &#39;   &#39;;
<a name="line128"></a>
<a name="line129"></a>  FIELD.makeEditable();
<a name="line130"></a>  assertEquals(&#39;field contains unexpected contents&#39;,
<a name="line131"></a>      UPPERCASE_CONTENTS, FIELD.getElement().innerHTML.toUpperCase());
<a name="line132"></a>
<a name="line133"></a>  FIELD.makeUneditable();
<a name="line134"></a>  assertEquals(&#39;field contains unexpected contents&#39;,
<a name="line135"></a>      UPPERCASE_CONTENTS, goog.dom.getElement(&#39;field&#39;).innerHTML.toUpperCase());
<a name="line136"></a>}
<a name="line137"></a>
<a name="line138"></a>function testLoremIpsumInClickToEditMode() {
<a name="line139"></a>  // in click-to-edit mode, trogedit manages the editable state of the editor,
<a name="line140"></a>  // so we must manage lorem ipsum in uneditable mode too.
<a name="line141"></a>  FIELD.makeEditable();
<a name="line142"></a>
<a name="line143"></a>  assertEquals(&#39;field contains unexpected contents&#39;,
<a name="line144"></a>      UPPERCASE_CONTENTS, FIELD.getElement().innerHTML.toUpperCase());
<a name="line145"></a>
<a name="line146"></a>  FIELD.makeUneditable();
<a name="line147"></a>  assertEquals(&#39;field contains unexpected contents&#39;,
<a name="line148"></a>      UPPERCASE_CONTENTS, goog.dom.getElement(&#39;field&#39;).innerHTML.toUpperCase());
<a name="line149"></a>}
<a name="line150"></a>
<a name="line151"></a>function getNbsp() {
<a name="line152"></a>  // On WebKit (pre-528) and Opera, &amp;nbsp; shows up as its unicode character in
<a name="line153"></a>  // innerHTML under some circumstances.
<a name="line154"></a>  return (goog.userAgent.WEBKIT &amp;&amp; !goog.userAgent.isVersionOrHigher(&#39;528&#39;)) ||
<a name="line155"></a>         goog.userAgent.OPERA ? &#39;\u00a0&#39; : &#39;&amp;nbsp;&#39;;
<a name="line156"></a>}
</pre>


</body>
</html>
